function [err] = set_vcpar()

htag = findobj('Tag', 'CTL');
sf = get(htag, 'Value');
if(sf <= 0) return;
end
QueMessage('Setting VC Parameters', 1);
for i = 1:length(sf)
    err = set_vcpar2(sf(i));
end;
return;

function [err] = set_vcpar2(sflag)

global CONTROL
err = 0;
QueMessage(sprintf('VC parameters for %s: %d', CONTROL(sflag).filename, CONTROL(sflag).recbeg));
CONTROL(sflag).jpot=0; % kgluc
CONTROL(sflag).mode='VC';
% set timing according to the protocol we have
prot = unblank(CONTROL(sflag).protocol);
switch(prot)
    case {'iv', 'vciv', 'vc_iv'}
        CONTROL(sflag).durho=10;
        CONTROL(sflag).durs1=100;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
     case {'vciv2', 'vc_iv2'}
        CONTROL(sflag).durho=10;
        CONTROL(sflag).durs1=200;
        CONTROL(sflag).durs2=100;
        CONTROL(sflag).durs3=100;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        CONTROL(sflag).leakwin = 0;
        CONTROL(sflag).transwin = 0;
        QueMessage(sprintf('Durations for %s', prot));       
    case 'mc-inact'
        CONTROL(sflag).durho=5;
        CONTROL(sflag).durs1=100;
        CONTROL(sflag).durs2=300;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
    case {'drug'}   
        CONTROL(sflag).durho=70;
        CONTROL(sflag).durs1=100;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
    case 'qinactp1'
        CONTROL(sflag).durho=5;
        CONTROL(sflag).durs1=100;
        CONTROL(sflag).durs2=100;
        CONTROL(sflag).durs3=100;
        CONTROL(sflag).transwdur=99;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).transwin=2;
        CONTROL(sflag).leakwin=3;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
    case 'qinactp2'
        CONTROL(sflag).durho=5;
        CONTROL(sflag).durs1=100;
        CONTROL(sflag).durs2=300;
        CONTROL(sflag).durs3=100;
        CONTROL(sflag).transwdur=99;
        CONTROL(sflag).transwin=2;
        CONTROL(sflag).leakwin=3;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
    case 'mc-qinactp2'
        CONTROL(sflag).durho=5;
        CONTROL(sflag).durs1=300;
        CONTROL(sflag).durs2=300;
        CONTROL(sflag).durs3=100;
        CONTROL(sflag).transwdur=299;
        CONTROL(sflag).transwin=2;
        CONTROL(sflag).leakwin=3;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
    case 'mc-qinactp3'
        CONTROL(sflag).durho=5;
        CONTROL(sflag).durs1=100;
        CONTROL(sflag).durs2=300;
        CONTROL(sflag).durs3=300;
        CONTROL(sflag).transwdur=99;
        CONTROL(sflag).transwin=2;
        CONTROL(sflag).leakwin=3;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
        
    case 'vc_spont'
        CONTROL(sflag).durho=1;
        CONTROL(sflag).durs1=50;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).transwdur=10;
        CONTROL(sflag).transwin=0;
        CONTROL(sflag).leakwin=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
        
    case 'epsccov'
        CONTROL(sflag).durho=75;
        CONTROL(sflag).durs1=25;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).transwdur=10;
        CONTROL(sflag).transwin=0;
        CONTROL(sflag).leakwin=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
        
    case 'EPSC_rect'
        CONTROL(sflag).durho=10;
        CONTROL(sflag).durs1=200;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).transwdur=10;
        CONTROL(sflag).transwin=0;
        CONTROL(sflag).leakwin=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).stim_time = 100;
        CONTROL(sflag).psp_time = [101 102];
        CONTROL(sflag).deadwin = 0.55;
        CONTROL(sflag).mode='VC';
        QueMessage(sprintf('Durations for %s', prot));
        
        
    case 'shockio'
        CONTROL(sflag).durho=75;
        CONTROL(sflag).durs1=25;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).transwdur=10;
        CONTROL(sflag).transwin=0;
        CONTROL(sflag).leakwin=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).stim_time = [5];
        CONTROL(sflag).psp_time = [5 10];
        CONTROL(sflag).deadwin = 0.7
        CONTROL(sflag).mode='VC';
        dfile = datac('getdfile'); % read the local dfile for data in memory
        [sf, df] = block_info(sflag);
        nstim = length(sf.waveform);
        vmax = 0;
        for i = 1: nstim
            dmax = floor(max(abs(sf.waveform{i}.v2))*100);
            if(dmax > vmax)
                vmax = dmax;
            end;
            if(i > 1)
                CONTROL(sflag).sequence = [CONTROL(sflag).sequence sprintf(',%d', vmax)];
            else
                CONTROL(sflag).sequence = sprintf('%d', vmax);
            end;
        end;
        CONTROL(sflag).sequence = deblank(CONTROL(sflag).sequence); % be sure - no spaces
        QueMessage(sprintf('Durations for %s', prot));
      
    case 'hpc_ltpvc_base'
        CONTROL(sflag).durho=110;
        CONTROL(sflag).durs1=10;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).transwdur=10;
        CONTROL(sflag).transwin=0;
        CONTROL(sflag).leakwin=0;
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).mode='VC';
        CONTROL(sflag).psp_time = [5 8 30 70];
        CONTROL(sflag).stim_time = [5];
        QueMessage(sprintf('Durations for %s', prot));

        
    case 'recovery'
        CONTROL(sflag).durho=75;
        CONTROL(sflag).durs1=25;
        CONTROL(sflag).durs2=0;
        CONTROL(sflag).durs3=0;
        CONTROL(sflag).transwdur=10;
        CONTROL(sflag).transwin=0;
        CONTROL(sflag).leakwin=0;
        CONTROL(sflag).deadwin=0.70; 
        CONTROL(sflag).vlmax=-70;
        CONTROL(sflag).vlmin=-100;
        CONTROL(sflag).stim_time = [5];
        CONTROL(sflag).psp_time = [6 10]; % set some default values in case we crash.
        CONTROL(sflag).mode='VC';
        [sf, df] = block_info(sflag); % get the stimfile and dfile we need for this block.
        if(isempty(sf))
            return;
        end;
        nstim = length(sf.waveform); % how many stimuli were created in the run?
        vmax = 0;
        si = [];
        for i = 1: nstim
            si = [si find(sf.waveform{i}.v2 > 0)];
        end;
        su = unique(si); % find the unique values
        ns = [];
        for i = 1:length(su) % find out how many times each stimulus was given.
            ns(i) = length(find(si == su(i)));
        end;
        maxn = max(ns); % these were given EVERY TIME!
        tb = sf.tbase{1}.v; % assumes every one is the same....
        ts = tb(su(find(ns == maxn)));
        CONTROL(sflag).stim_time = ts; % these are the stimulus times that were repeated every time
        if(length(ts > 1))
            CONTROL(sflag).psp_time = [ts(1) ts(2)-0.5]; % set psp window (except for deadtime). 
        else
            CONTROL(sflag).psp_time = [ts(1) ts(1)+10];
        end;
        tt = tb(su(find(ns<maxn)));
        for i = 1:length(tt)
            if(i > 1)
                CONTROL(sflag).sequence = [CONTROL(sflag).sequence sprintf(',%.1f', tt(i))];
            else
                CONTROL(sflag).sequence = sprintf('%.1f', tt(i));
            end;
        end;
        CONTROL(sflag).sequence = deblank(CONTROL(sflag).sequence); % be sure - no spaces
        QueMessage(sprintf('test times extracted for %s', prot));
        
    otherwise
        QueMessage(sprintf('set_vcpar: Protocol <%s> is not known for VC', prot));
        % DO NOTHING if protocol is NOT in the list.....
end;


return;
